import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
const store = new Vuex.Store({
  state: {
    userId: {},
    token: null,
    cname: ''
  },
  mutations: {
    LOGIN: (state, data) => {
      localStorage.token = data.token;
      state.token = data.token;
      state.userId = data.userId;
      state.cname = data.cname;
    },
    LOGOUT: (state) => {
      localStorage.removeItem('token');
      state.token = null
    },
    TITLE: (state, data) => {
      state.title = data;
    }
  },
  actions: {
    login({ commit }, app) {
      commit("LOGIN", app);
    },
    loginOut({ commit }, app) {
      commit("LOGOUT", app);
    }
  }
});
export default store;
